/**
 * Copyright &copy; 2015-2020 <a href="http://www.easyhis.com/">easyhis</a> All rights reserved.
 */
package com.easy.modules.sys.entity;

import com.easy.common.utils.IdGen;
import com.easy.common.utils.excel.annotation.ExcelField;
import com.easy.core.persistence.BaseEntity;
import com.easy.modules.sys.utils.UserUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import org.hibernate.validator.constraints.Length;

import java.util.Date;
import java.util.List;

/**
 * 数据字典Entity
 * @author lgf
 * @version 2017-01-16
 */
public class DictType extends BaseEntity<DictType> {
	
	private static final long serialVersionUID = 1L;
	private Integer typeId;
	private String id;
	private String typeName;		// 类型
	private String typeDesc;		// 描述
	private List<Dict> dictList = Lists.newArrayList();		// 子表列表
	protected User createBy;	// 创建者
	protected Date createTime;	// 创建日期
	protected User updateBy;	// 更新者
	protected Date updateTime;	// 更新日期
	protected String delFlag; 	// 删除标记（0：正常；1：删除；2：审核）

	
	public DictType() {
		super();
	}

	public DictType(Integer typeId){
		this.typeId = typeId;
	}

	public DictType(String id){
		this.id = id;
	}

	public Integer getTypeId() {
		return typeId;
	}

	public void setTypeId(Integer typeId) {
		this.typeId = typeId;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@ExcelField(title="类型", align=2, sort=1)
	public String getTypeName() {
		return typeName;
	}

	public void setTypeName(String typeName) {
		this.typeName = typeName;
	}
	
	@ExcelField(title="描述", align=2, sort=2)
	public String getTypeDesc() {
		return typeDesc;
	}

	public void setTypeDesc(String typeDesc) {
		this.typeDesc = typeDesc;
	}
	
	public List<Dict> getDictList() {
		return dictList;
	}

	public void setDictList(List<Dict> dictList) {
		this.dictList = dictList;
	}

	public User getCreateBy() {
		return createBy;
	}

	public void setCreateBy(User createBy) {
		this.createBy = createBy;
	}

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public User getUpdateBy() {
		return updateBy;
	}

	public void setUpdateBy(User updateBy) {
		this.updateBy = updateBy;
	}

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	@JsonIgnore
	@Length(min=1, max=1)
	public String getDelFlag() {
		return delFlag;
	}

	public void setDelFlag(String delFlag) {
		this.delFlag = delFlag;
	}

	/**
	 * 插入之前执行方法，需要手动调用
	 */
	public void preInsert(){
		this.id = IdGen.uuid();
		User user = UserUtils.getUser();
		if (user.getUserId()<1){
			this.updateBy = user;
			this.createBy = user;
		}
		this.updateTime = new Date();
		this.createTime = this.updateTime;
	}

	/**
	 * 更新之前执行方法，需要手动调用
	 */
	public void preUpdate(){
		User user = UserUtils.getUser();
		if (user.getUserId()<1){
			this.updateBy = user;
		}
		this.updateTime = new Date();
	}


}